'''
连接数据库，需要安装pymysql
连接数据库，创建一个连接对象
'''
import pymysql
con = pymysql.connect(host='localhost',
                      user='root',
                      password='root',
                      port=3306,
                      database='girls')
# 根据连接对象，创建游标（询问）对象
cur = con.cursor()
#执行sql语句
cur.execute('select * from beauty') # 这一行是执行不出结果集的，需要获取多条查询结果

# 获取多条查询结果  fetchall
# res = cur.fetchall()
# print(res)
# for n in res:
#     print(n)

# # 从beauty表里查询叫王语嫣的信息
# cur.execute("select * from beauty where name='王语嫣'")
# #查询一条数据
# res = cur.fetchone()
# print(res)
#
# # 查询迪丽热巴的电话号码
# cur.execute("select phone from beauty where name='热巴'") # 查询语句
# res = cur.fetchone() # 获取单个查询结果语句
# print(res) # 当元组数据只有一个的时候要多加个逗号
#
# # 查询王语嫣的男朋友
# cur.execute("select boyName from beauty inner join boys on beauty.boyfriend_id=boys.id where name='王语嫣'")
# res = cur.fetchone() # 获取单个查询结果语句
# print(res)
#
# # 把鹿晗的userCP改成200
# cur.execute("update boys set userCP=200 where boyname='鹿晗'")
# # 修改后需要提交才能成功
# con.commit()
#
# # 添加数据
# # 添加一个周杰伦 999
# # cur.execute("insert into boys(boyName,userCP) values('周杰伦',999)")
# # # 增加数据后需要提交才能成功
# # con.commit()

# 删除数据 删除id=5的数据
# cur.execute("delete from boys where id=5")
# # 增加数据后需要提交才能成功
# con.commit()

# # 关闭游标对象
# cur.close()
# # 关闭连接对象
# con.close()
# 读取数据
# name = '苍老师'
# name = '柳岩'
# # 查询phone
# cur.execute(f"select phone from beauty where name='{name}'")
# res = cur.fetchone() # 获取单个查询结果语句
# print(res)

a = 'k','b','c','d','u'
for n in a:
    print(a)

